using Microsoft.AspNetCore.Builder;
using WebApplication1.chat;
using WebApplication1.Service;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpClient("video");
builder.Services.AddSingleton<ChatService>();
builder.Services.AddCors(s => {
    s.AddPolicy("test", a =>
    {
        a.SetIsOriginAllowed(s=>true).AllowAnyHeader().AllowAnyMethod().AllowCredentials();
    });
});
builder.Services.AddSignalR();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseCors("test");
app.Use(async(a, b) =>
{
  await b();
});
app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();
app.MapHub<VideoHub>("video");
app.Run();
